class Solution
{
public:
    bool judgeSquareSum(int c)
    {
        int upper = sqrt(c);
        unordered_set<int> comp;
        for (int i = 0; i <= upper; ++i)
        {
            int square = i * i;
            comp.insert(c - square);
            if (comp.count(square))
            {
                return true;
            }
        }
        return false;
    }
};